﻿#include "line.h"
#include <QPen>
#include <QBrush>
#include <QDebug>
#include "../include/dxf/dl_codes.h"
namespace Entities
{

Line::Line()
{
}

Line::Line(const Point&p1,const Point&p2)
{
    m_startPoint=p1;
    m_endPoint=p2;
}

Line::Line(const Line& line)
{
    m_startPoint=line.GetStartPoint();
    m_endPoint=line.GetEndPoint();
    SetAttributes(line.GetAttributes());
}

Line::~Line()
{

}
void Line::printInfo(){
    qDebug()<<"Line重要数据打印";
    m_startPoint.printInfo();
    m_endPoint.printInfo();
}
void Line::writeDxfInfo(DL_Dxf &dxf, DL_WriterA* dw){
    Attributes a = GetAttributes();
    printInfo();
    DL_LineData data(m_startPoint.GetX(), m_startPoint.GetY(), m_startPoint.GetZ(),
                     m_endPoint.GetX(), m_endPoint.GetY(), m_endPoint.GetZ());
    dxf.writeLine(*dw, data, DL_Attributes(a.layer_name, a.color, a.line_width, a.line_type, 1.0));
}
void Line::Draw(QPainter& painter)
{
    QPen pen;
    QColor rgb(dxfColors[m_attributes.color][0]*255, dxfColors[m_attributes.color][1]*255, dxfColors[m_attributes.color][2]*255);
   // qDebug()<<"Line::Draw=====>"<<m_attributes.color<<m_attributes.line_type.c_str()<<m_attributes.getLineType();
    pen.setColor(rgb);
    pen.setWidth(m_attributes.line_width);
    pen.setStyle((Qt::PenStyle)m_attributes.getLineType());
    painter.setPen(pen);
    QPoint p1(round(m_startPoint.GetDrawableX()),round(m_startPoint.GetDrawableY()));
    QPoint p2(m_endPoint.GetDrawableX(),m_endPoint.GetDrawableY());
    painter.drawLine(p1,p2);
}

Entity* Line::Clone()
{
    Entity* line=new Line(*this);
    return line;
}

void Line::Transform(double*params,int size)
{
    m_startPoint.Transform(params,size);
    m_endPoint.Transform(params,size);
}

void Line::Scale(double ratio)
{
    m_startPoint.Scale(ratio);
    m_endPoint.Scale(ratio);
}

void Line::Transfer(double dx,double dy,double dz)
{
    m_startPoint.Transfer(dx,dy,dz);
    m_endPoint.Transfer(dx,dy,dz);
}

void Line::Rotate(double angle,double cx,double cy,double cz)
{

}

void  Line::mouseDoubleClickEvent(QMouseEvent *event)
{

}

void Line::mouseMoveEvent(QMouseEvent *event)
{

}

void Line::mousePressEvent(QMouseEvent *event)
{

}

void Line::mouseReleaseEvent(QMouseEvent *event)
{

}

void Line::dragEnterEvent(QDragEnterEvent *event)
{

}

void Line::dragMoveEvent(QDragMoveEvent *event)
{

}

void Line::dragLeaveEvent(QDragLeaveEvent *event)
{

}

void Line::dropEvent(QDropEvent *event)
{

}

void Line:: wheelEvent(QWheelEvent*event)
{

}
void Line:: CorrectCoord(double bx,
                         double by,
                         double bz,
                         double sx,
                         double sy,
                         double sz,
                         double rotaAngle)
{
    m_startPoint.CorrectCoord(bx,by,bz,sx,sy,sz,rotaAngle);
    m_endPoint.CorrectCoord(bx,by,bz,sx,sy,sz,rotaAngle);
}

}
